package com.lzxuni.modules.informationpublish.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzxuni.common.utils.StringUtils;
import com.lzxuni.modules.common.entity.FileEntity;
import com.lzxuni.modules.common.entity.PageParameter;
import com.lzxuni.modules.informationpublish.entity.InformationPublishPressRelease;
import com.lzxuni.modules.informationpublish.mapper.InformationPublishPressReleaseMapper;
import com.lzxuni.modules.informationpublish.service.InformationPublishPressReleaseService;
import com.lzxuni.modules.system.entity.BaseArea;
import com.lzxuni.modules.system.mapper.BaseAreaMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fcd
 * @since 2019-06-25
 */
@Service
public class InformationPublishPressReleaseServiceImpl extends ServiceImpl<InformationPublishPressReleaseMapper, InformationPublishPressRelease> implements InformationPublishPressReleaseService {
    @Autowired
    private InformationPublishPressReleaseMapper informationPublishPressReleaseMapper;
    @Autowired
    private BaseAreaMapper areaMapper;
    @Override
    public PageInfo<InformationPublishPressRelease> queryPage(PageParameter pageParameter, InformationPublishPressRelease informationPublishPressRelease) throws SQLException {
        PageHelper.startPage(pageParameter.getPage(), pageParameter.getRows()).setOrderBy(
                pageParameter.getSidx() + " " + pageParameter.getSord());
        List<InformationPublishPressRelease> list;
        if (StringUtils.isNotEmpty(informationPublishPressRelease.getNewsTitle())) {
            list = baseMapper.selectList(new QueryWrapper<InformationPublishPressRelease>().like("news_title", informationPublishPressRelease.getNewsTitle()).eq("news_type","news"));
        }else {
            list = baseMapper.selectList(new QueryWrapper<InformationPublishPressRelease>().eq("news_type","news"));
        }
        for (InformationPublishPressRelease situation : list) {
            BaseArea area = areaMapper.selectById(situation.getNewsId());
            if (area != null) {
                situation.setProName(area.getAreaName());
            }
        }
        PageInfo<InformationPublishPressRelease> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<InformationPublishPressRelease> queryPages(PageParameter pageParameter, InformationPublishPressRelease informationPublishPressRelease) throws SQLException {
        PageHelper.startPage(pageParameter.getPage(), pageParameter.getRows()).setOrderBy(
                pageParameter.getSidx() + " " + pageParameter.getSord());
        List<InformationPublishPressRelease> list;
        if (StringUtils.isNotEmpty(informationPublishPressRelease.getNewsTitle())) {
            list = baseMapper.selectList(new QueryWrapper<InformationPublishPressRelease>().like("news_title", informationPublishPressRelease.getNewsTitle()).eq("news_type","bgt"));
        }else {
            list = baseMapper.selectList(new QueryWrapper<InformationPublishPressRelease>().eq("news_type","bgt"));
        }
        for (InformationPublishPressRelease situation : list) {
            BaseArea area = areaMapper.selectById(situation.getNewsId());
            if (area != null) {
                situation.setProName(area.getAreaName());
            }
        }
        PageInfo<InformationPublishPressRelease> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
    @Override
    public PageInfo<InformationPublishPressRelease> queryPagebm(PageParameter pageParameter, String newsType) {
        PageHelper.startPage(pageParameter.getPage(), pageParameter.getRows()).setOrderBy(
                pageParameter.getSidx() + " " + pageParameter.getSord());
        List<InformationPublishPressRelease> list = baseMapper.queryListtype(newsType);
//        List<InformationPublishPressRelease> list = baseMapper.selectList(new QueryWrapper<InformationPublishPressRelease>().eq("news_type", newsType).groupBy("news_id").orderByDesc("create_time"));
        PageInfo<InformationPublishPressRelease> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }


}
